import 'package:flutter/material.dart';
import 'package:todo_app/components/TextExt.dart';
import 'package:todo_app/constants/DColor.dart';
import 'package:todo_app/constants/ImageAssets.dart';
import 'package:todo_app/controllers/definitions/TodoModel.dart';
import 'package:todo_app/layout/CustomCard.dart';
import 'package:todo_app/layout/Gaps.dart';
import 'package:todo_app/layout/ListItem.dart';
import 'package:todo_app/utils/AppNavigator.dart';
import 'package:todo_app/utils/ExtHelper.dart';

class TodoWidget extends StatelessWidget {
  final TodoModel todo;

  const TodoWidget({super.key, required this.todo});
  @override
  Widget build(BuildContext context) {
    return CustomCard(
      borderRadius: 4.dp,
      margin: EdgeInsets.only(
        bottom: 10.dp,
        left: 15.dp,
        right: 15.dp
      ),
      child: ListItem(
        height: 72.dp,
        padding: EdgeInsets.symmetric(horizontal: 15.dp),
        icon: ClipRRect(
          borderRadius: BorderRadius.circular(4.dp),
          child: Image.asset(ImageAssets.commonLogoPng, width: 44.dp)
        ),
        onTap: () {
          AppNavigator.pushNamed('todoDetail', params: { 'id': todo.id.toString() });
        },
        title: TextExt.title(
          todo.title ?? "", 
          bold: true, 
          fontSize: 14.dp,
          lineHeight: 20 / 14
        ),
        subtitle: TextExt.desc(todo.content ?? "", maxLines: 2, lineHeight: 20 / 14),
        actions: [
          Text(
            todo.alertTime.toMD(),
            style: TextStyle(
              fontSize: 12.dp,
              color: DColor.body
            ),
          )
        ],
        nextIcon: true,
      ),
    );
  }
}
